﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

using H2.NET.Controls;
using H2.NET.Business;
using H2.NET.Data.Common;
using H2.NET.Business.DMO.Concur_Master;

namespace H2.NET.Web.Pages
{
    public partial class PCONQ : TaskPage
    {
        #region 属性 Public
        private bool IsLoaded
        {
            get
            {
                return ViewState["IsLoaded"] == null ? false : (bool)ViewState["IsLoaded"];
            }
            set { ViewState["IsLoaded"] = value; }
        }
        #endregion

        #region 事件 Page_Load(页面加载)
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                INFO.Text = string.Format("<br/>表单正在被同事“{0}”抢占处理，拒绝提交！", RobUser);
                INFO.Visible = IsOverFlow;

                //InitDropDownList();
                bool flg = (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) ? true : false;
                
                #region 发起步骤
                if ((TaskAPI.IsBeginStep&& TaskAPI.IsAllowSubmit))
                {
                    InitDropDownList();
                    SetColor();
                }              
                #endregion

                #region 审批环节
                if (!TaskAPI.IsInitiate)
                {
                    #region 加载数据并显示
                    Con_Concur vendor = (Con_Concur.process == TaskAPI.Process & Con_Concur.incident == TaskAPI.Incident).ListFirst<Con_Concur>();
                    if (vendor != null)
                    {
                        SetDropDownListValue(Actions, vendor.Actions);
                        SetColor();
                        ApplicationNo.Text = vendor.ApplicationNo;
                        Actions.SelectedValue = vendor.Actions;

                        SA_Expense_User.Checked = vendor.SA_Expense_User == "1";
                        SA_Expense_Approver.Checked = vendor.SA_Expense_Approver == "1";

                        SetDropDownListValue(SA_State_Province, vendor.SA_State_Province);
                        SetDropDownListValue(SA_Legal_Entity, vendor.SA_Legal_Entity);
                        SetDropDownListValue(SA_Location, vendor.SA_Location);

                        SA_Employee_Grouping.Text = vendor.SA_Employee_Grouping;
                        SA_Employee_Group_Configuration.Text = vendor.SA_Employee_Group_Configuration;
                        SA_First_Name.Text = vendor.SA_First_Name;
                        SA_Last_Name.Text = vendor.SA_Last_Name;
                        SA_CTE_Login_Name.Text = vendor.SA_CTE_Login_Name;
                        SA_Account_Activation_Date.Text = vendor.SA_Account_Activation_Date;
                        SA_Account_Termination_Date.Text = vendor.SA_Account_Termination_Date;
                        SA_Employee_ID.Text = vendor.SA_Employee_ID;
                        SA_Email_Address.Text = vendor.SA_Email_Address;
                        SA_Country.Text = vendor.SA_Country;
                        SA_Ledger.Text = vendor.SA_Ledger;
                        SA_Cost_Object_Type.Text = vendor.SA_Cost_Object_Type;
                        SA_ERP_ID.Text = vendor.SA_ERP_ID;
                        SA_Currency.Text = vendor.SA_Currency;
                        SA_Cost_Object_Code.Text = vendor.SA_Cost_Object_Code;
                        SA_Approver_Linemanager.Text = vendor.SA_Approver_Linemanager;
                        SA_SWIFT_BIN.Text = vendor.SA_SWIFT_BIN;
                        SA_Bank_Country_Concur.Text = vendor.SA_Bank_Country_Concur;
                        SA_IBAN_Number.Text = vendor.SA_IBAN_Number;
                        SA_Local_Personnel_Number.Text = vendor.SA_Local_Personnel_Number;
                        SA_Pay_Roll_ID.Text = vendor.SA_Pay_Roll_ID;
                        SA_Region_Concur.Text = vendor.SA_Region_Concur;
                        SA_Country_Concur.Text = vendor.SA_Country_Concur;
                        SA_Travel_Rule.Text = vendor.SA_Travel_Rule;
                        SA_Business_Area.Text = vendor.SA_Business_Area;
                        SA_Business_Unit.Text = vendor.SA_Business_Unit;
                        //SA_Sub_Business_Unit.Text = vendor.SA_Sub_Business_Unit;
                        SetDropDownListValue(SA_Sub_Business_Unit, vendor.SA_Sub_Business_Unit); //add by kim.zheng 2016-08-18
                        SA_Default_Lanuage.Text = vendor.SA_Default_Lanuage;


                    }
                    #endregion

                    #region 审批项初始化
                    switch(TaskAPI.Step)
                    {
                        

                        case "DMO Approve":
                        case "DMO Maintain":
                        case "DMO Check":
                            Assessment1.Option.Add(new t_AssessmentOption("Finish", "1", true));
                            Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));
                            break;

                        case "Manager Approve":                      
                            Assessment1.Option.Add(new t_AssessmentOption("Approve", "1", true));
                            Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));
                            break;
                        
                    }
                    #endregion
                }
                #endregion

                SetDefaultValue();

                #region 设置控件禁启用
                //bool flg = (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) ? true : false;

                SetEnable(flg, Actions, SA_Expense_Approver, SA_First_Name, SA_Last_Name, SA_CTE_Login_Name, SA_Account_Activation_Date, SA_Account_Termination_Date, SA_Employee_ID, SA_State_Province, SA_Legal_Entity, SA_Cost_Object_Code, SA_Approver_Linemanager, SA_SWIFT_BIN, SA_IBAN_Number);
                //SetEnable(TaskAPI.Step == "DMO Maintain", SAP_Code);
                Assessment1.Enable = TaskAPI.IsAllowSubmit;
                SetVisible(TaskAPI.IsAllowSubmit, Send, Split);

                //Modified by Tony 2016-03-24,Hu Na Requested
                //SetVisible(Actions.SelectedValue == "1", SA_Approver_Linemanager_L,SA_Approver_Linemanager);
                //SetVisible(Actions.SelectedValue == "1", P5);
                Attachment1.AllowDelete = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                Attachment1.AllowUpload = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
               
                //InitTabs();
                #endregion

                #region 加深颜色
                string item = null;
                string value = null;
                foreach (Control cr in this.Controls)
                {
                    if (cr is DropDownList)
                    {
                        DropDownList tb = (DropDownList)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            item = tb.SelectedItem.Text;
                            value = tb.SelectedValue.ToString();
                            tb.Items.Clear();
                            tb.Items.Add(new ListItem(item, value));
                        }
                        tb.ForeColor = System.Drawing.Color.DimGray;
                    }
                }
                if (!flg || !TaskAPI.IsAllowSubmit)
                {

                    foreach (Control cr in form.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in form.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }

                }

                #endregion
            }
        }
        #endregion

        #region 事件 Send
        protected void Send_Click(object sender, EventArgs e)
        {
            try
            {
                #region 数据验证
                if (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) // 如果是退回的情况，不存在验证
                {
                    List<string> vald_s = new List<string>();
                    vald_s.AddRange(DataValidation());
                    if (vald_s.Count > 0)
                    {
                        Anthem.Manager.AddScriptForClientSideEval(string.Format("ShowMessage(\"{0}\", {1});", CombineMessage(vald_s), vald_s.Count));
                        return;
                    }
                }
                #endregion

                #region 引擎传值
                if (TaskAPI.IsBeginStep)
                {
                    if (TaskAPI.IsInitiate)
                    {
                        ApplicationNo.Text        = Util.GenerateSequence(((object[])TaskAPI["PrefixNo"])[0].ToString() + "-" + System.DateTime.Now.ToString("yyMM"), "", 4);
                        TaskAPI.UserName          = UserAPI.UserName;
                        TaskAPI["ApplicationNo"]  = ApplicationNo.Text;
                        TaskAPI["ApplicatorName"] = UserAPI.UserFullName;
                        TaskAPI["Applicator"]     = UserAPI.UserName;
                        TaskAPI["Time"]           = System.DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
                        TaskAPI["ApplicatorEmail"] = UserAPI.Mail;
                        TaskAPI["Department"]     = UserAPI.Department;
                    }

                    TaskAPI.Summary = (Actions.SelectedItem.Text.Split(',').Length >= 2 ? Actions.SelectedItem.Text.Split(',')[1].Trim() : Actions.Text) + " / " + ApplicationNo.Text;
                    
                    TaskAPI["Actions"]        = Actions.SelectedValue;
                    TaskAPI["Remark_by_Initiator"] = Assessment1.Assessment.Remark;

                    #region 从数据库取得流程步骤处理人
                    SortedList<string, string> rec_a = new SortedList<string, string>();

                    IList<mdc_Recipient> rec_s = (mdc_Recipient.process == TaskAPI.Process & (mdc_Recipient.distribute == Actions.SelectedValue | mdc_Recipient.distribute == "*") & mdc_Recipient.status == 1).List<mdc_Recipient>();
                    foreach (mdc_Recipient rec in rec_s)
                    {
                        if (!rec_a.ContainsKey(rec.Step))
                        {
                            rec_a.Add(rec.Step, rec.Recipient);
                            continue;
                        }

                        if (rec_a.Values[rec_a.IndexOfKey(rec.Step)].Contains(rec.Recipient))
                        {
                            continue;
                        }

                        rec_a[rec.Step] = rec_a.Values[rec_a.IndexOfKey(rec.Step)] + "," + rec.Recipient;
                    }

                    //步骤处理人赋值
                    for (int i = 0; i < rec_a.Keys.Count; i++)
                    {
                        TaskAPI["R_" + rec_a.Keys[i].Replace(" ", "_")] = rec_a.Values[i].Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    }

                    m_OrgChart oc = (m_OrgChart.empID.In(m_OrgChart.dr2EmpID, m_OrgChart.winID == UserAPI.UserName)).ListFirst<m_OrgChart>();
                    if (oc != null)
                    {
                        TaskAPI["R_Manager_Approve"] = oc.WinID;
                    }

                    #endregion
                }
                else
                {
                    TaskAPI["ApproveResult"] = Assessment1.Assessment.Opinion;
                    TaskAPI["TaskID"]        = TaskAPI.TaskID;
                }

                //if (TaskAPI.IsBeginStep && !TaskAPI.IsInitiate
                //&& (Action_Type != Actions.SelectedValue || account_Type != VD_account_Type.SelectedValue))
                //{
                //    string PreStep = ((object[])TaskAPI["PreStep"])[0].ToString();
                //    if (PreStep.Trim() != "" && PreStep.Trim() != "Manager Approve")
                //    {
                //        TaskAPI["PreStep"] = "DMO Approve";
                //    }
                //}

                //#region 退回步骤并返回功能 传值
                //if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                //{
                //    TaskAPI["Step"] = Assessment1.JumpStep;
                //    TaskAPI["PreStep"] = TaskAPI.Step;
                //}
                //else
                //{
                //    string PreStep = ((object[])TaskAPI["PreStep"])[0].ToString();
                //    if (PreStep.Trim() != "")
                //    {
                //        TaskAPI["Step"]    = PreStep;
                //        TaskAPI["PreStep"] = "";
                //    }
                //    else
                //    {
                //        TaskAPI["Step"] = "";
                //        TaskAPI["PreStep"] = "";
                //    }
                //}
                //#endregion

                #endregion

                #region 提交步骤
                bool flg=false;
                Storage.TransactionExecute(o =>
                {
                    #region “Fill in the form”步骤
                    if (TaskAPI.IsBeginStep)
                    {
                        Con_Concur vendor = new Con_Concur();
                        if ((Con_Concur.process == TaskAPI.Process & Con_Concur.incident == TaskAPI.Incident & Con_Concur.userName == UserAPI.UserName).Count<Con_Concur>() > 0)
                        {
                            vendor = (Con_Concur.process == TaskAPI.Process & Con_Concur.incident == TaskAPI.Incident & Con_Concur.userName == UserAPI.UserName).ListFirst<Con_Concur>();
                        }
                        else
                        {
                            vendor.Process = TaskAPI.Process;
                            vendor.Incident = TaskAPI.Incident;
                            vendor.UserName = UserAPI.UserName;
                            vendor.UserFullName = UserAPI.UserFullName;
                            vendor.ApplicationNo = ApplicationNo.Text;
                            vendor.Time = System.DateTime.Now;
                            vendor.Status = 0;
                            vendor.Department = UserAPI.Department;
                        }

                        vendor.Actions = Actions.SelectedValue;
                        vendor.Actions = Actions.SelectedItem.Text;

                        vendor.Actions = Actions.SelectedValue;

                        vendor.SA_Expense_User = SA_Expense_User.Checked ? "1" : "0";
                        vendor.SA_Expense_Approver = SA_Expense_Approver.Checked ? "1" : "0";
                        vendor.SA_State_Province = SA_State_Province.SelectedValue;
                        vendor.SA_Legal_Entity = SA_Legal_Entity.SelectedValue;
                        vendor.SA_Location = SA_Location.SelectedValue;

                        vendor.SA_Employee_Grouping = SA_Employee_Grouping.Text;
                        vendor.SA_Employee_Group_Configuration = SA_Employee_Group_Configuration.Text;
                        vendor.SA_First_Name = SA_First_Name.Text;
                        vendor.SA_Last_Name = SA_Last_Name.Text;
                        vendor.SA_CTE_Login_Name = SA_CTE_Login_Name.Text;
                        vendor.SA_Account_Activation_Date = SA_Account_Activation_Date.Text;
                        vendor.SA_Account_Termination_Date = SA_Account_Termination_Date.Text;
                        vendor.SA_Employee_ID = SA_Employee_ID.Text;
                        vendor.SA_Email_Address = SA_Email_Address.Text;
                        vendor.SA_Country = SA_Country.Text;
                        vendor.SA_Ledger = SA_Ledger.Text;
                        vendor.SA_Cost_Object_Type = SA_Cost_Object_Type.Text;
                        vendor.SA_ERP_ID = SA_ERP_ID.Text;
                        vendor.SA_Currency = SA_Currency.Text;
                        vendor.SA_Cost_Object_Code = SA_Cost_Object_Code.Text;
                        vendor.SA_Approver_Linemanager = SA_Approver_Linemanager.Text;
                        vendor.SA_SWIFT_BIN = SA_SWIFT_BIN.Text;
                        vendor.SA_Bank_Country_Concur = SA_Bank_Country_Concur.Text;
                        vendor.SA_IBAN_Number = SA_IBAN_Number.Text;
                        vendor.SA_Local_Personnel_Number = SA_Local_Personnel_Number.Text;
                        vendor.SA_Pay_Roll_ID = SA_Pay_Roll_ID.Text;
                        vendor.SA_Region_Concur = SA_Region_Concur.Text;
                        vendor.SA_Country_Concur = SA_Country_Concur.Text;
                        vendor.SA_Travel_Rule = SA_Travel_Rule.Text;
                        vendor.SA_Business_Area = SA_Business_Area.Text;
                        vendor.SA_Business_Unit = SA_Business_Unit.Text;
                        vendor.SA_Sub_Business_Unit = SA_Sub_Business_Unit.SelectedValue; //add by kim.zheng 2016-08-18
                        vendor.SA_Default_Lanuage = SA_Default_Lanuage.Text;
                        

                        (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username == UserAPI.UserName).Edit<t_Attachment>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });

                        Storage.Save(Storage.Context1, vendor);
                    }
                    #endregion

                    //#region “DMO Maintain”步骤
                    //if (TaskAPI.Step == "DMO Maintain")
                    //{
                    //    (gla_GLAccount.process == TaskAPI.Process & gla_GLAccount.incident == TaskAPI.Incident).Edit<gla_GLAccount>(p =>
                    //    {
                    //        p.SAP_Code = SAP_Code.Text;
                    //    }    
                    //    );
                    //}
                    //#endregion

                    Storage.Save(Assessment1.Assessment);    //审批意见

                    //多节点退回
                    if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                    {
                        Assessment1.SetAsReturn(true);
                        TaskAPI.DirectActive(Assessment1.JumpStep);
                    }
                    else
                    {
                        Assessment1.SetAsReturn(false);
                    }
                    Assessment1.SubmitTo();

                    flg = TaskAPI.Send();
                });

                //如果数据库写入成功且流程发起成功的情况，将业务表数据与流程实例号进行关联
                if (TaskAPI.IsInitiate)
                {
                    (Con_Concur.process == TaskAPI.Process & Con_Concur.incident == 0 & Con_Concur.userName == UserAPI.UserName).Edit<Con_Concur>(p => 
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (t_Assessment.process == TaskAPI.Process & t_Assessment.incident == 0 & t_Assessment.assignedToUserName == UserAPI.UserName).Edit<t_Assessment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username == UserAPI.UserName).Edit<t_Attachment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                }
                #endregion

                Send.Visible = false;
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Success + "',true)");
            }
            catch (Exception ex)
            {
                TaskDB.Log("", false, "调用NVA方法Send_Click出错：" + ex.ToString());
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Failed + "',false)");
            }
        }
        #endregion

        #region 事件 Actions 变换
        protected void Actions_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetColor();
            SetEnable((Actions.SelectedValue == "1" || Actions.SelectedValue == "2" || Actions.SelectedValue == "3" || Actions.SelectedValue == "4"));
            //SetVisible(Actions.SelectedValue == "1", P5);

            //Modified by Tony 2016-03-24,Hu Na Requested
            //SetVisible(Actions.SelectedValue == "1", SA_Approver_Linemanager_L, SA_Approver_Linemanager);
        }
        #endregion

        #region 方法 SetColor
        protected void SetColor()
        {
            SetForeColor(Color.Black, SA_First_Name_L, SA_Last_Name_L, SA_CTE_Login_Name_L, SA_Account_Activation_Date_L, SA_Employee_ID_L, SA_State_Province_L, SA_Legal_Entity_L, SA_Cost_Object_Code_L, SA_Approver_Linemanager_L, SA_SWIFT_BIN_L, SA_IBAN_Number_L, SA_Sub_Business_Unit_L);
            switch (Actions.SelectedValue)
            {
                case "1":
                    SetForeColor(Color.Blue, SA_First_Name_L, SA_Last_Name_L, SA_CTE_Login_Name_L, SA_Account_Activation_Date_L, SA_Employee_ID_L, SA_State_Province_L, SA_Legal_Entity_L, SA_Cost_Object_Code_L, SA_Approver_Linemanager_L, SA_SWIFT_BIN_L, SA_IBAN_Number_L, SA_Sub_Business_Unit_L);
                    break;

                case "2":
                    SetForeColor(Color.Blue, SA_CTE_Login_Name_L, SA_Employee_ID_L, SA_Sub_Business_Unit_L);
                    break;

                case "3":
                    SetForeColor(Color.Blue, SA_CTE_Login_Name_L, SA_Employee_ID_L, SA_Sub_Business_Unit_L);
                    break;

                case "4":
                    SetForeColor(Color.Blue, SA_CTE_Login_Name_L, SA_Employee_ID_L, SA_Sub_Business_Unit_L);
                    break;

               
            }
        }
        #endregion

        #region 方法 SetDefaultValue(设置默认值, 并禁用输入)
        public void SetDefaultValue()
        {
            SA_Employee_Grouping.Text = "Local Employee";
            SA_Employee_Group_Configuration.Text="CN";
            SA_Expense_User.Checked=true;
            SA_Country.Text = "CHINA";
            SA_Ledger.Text = "SCOA";
            SA_Cost_Object_Type.Text = "Cost Center";
            SA_ERP_ID.Text= "CDE_100 Z1085CNY01) SAP";
            SA_Currency.Text = "CNY";
            SA_Bank_Country_Concur.Text = "CN";
            SA_Pay_Roll_ID.Text = "PCN0";
            SA_Region_Concur.Text = "Asia";
            SA_Country_Concur.Text = "CNChina";
            SA_Travel_Rule.Text = "Expense Only";
            SA_Business_Area.Text = "BA Decorative Paints";
            SA_Business_Unit.Text = "DP China and North Asia";
            //SA_Sub_Business_Unit.Text = "CN Mainland China";
            SA_Default_Lanuage.Text = "Chinese (China)";

            // change by kim.zheng 2016-08-18
            SetEnable(false, SA_Email_Address, SA_Local_Personnel_Number, SA_Employee_Grouping, SA_Employee_Group_Configuration, SA_Expense_User, SA_Country, SA_Ledger, SA_Cost_Object_Type, SA_ERP_ID, SA_Currency, SA_Bank_Country_Concur, SA_Pay_Roll_ID, SA_Region_Concur, SA_Country_Concur, SA_Travel_Rule, SA_Business_Area, SA_Business_Unit, SA_Default_Lanuage, SA_Location);
            SetForeColor(Color.Orange, SA_Employee_Grouping_L, SA_Employee_Group_Configuration_L, SA_Expense_User_L, SA_Country_L, SA_Ledger_L, SA_Cost_Object_Type_L, SA_ERP_ID_L, SA_Currency_L, SA_Bank_Country_Concur_L, SA_Pay_Roll_ID_L, SA_Region_Concur_L, SA_Country_Concur_L, SA_Travel_Rule_L, SA_Business_Area_L, SA_Business_Unit_L, SA_Default_Lanuage_L, SA_Location_L);
        }
        #endregion
    
        #region 方法 InitDropdownList
        private void InitDropDownList()
        {
            if (!IsLoaded)
            {
                //Account_Currency.Items.Clear();
                //Account_Currency.Items.Add(new ListItem("", ""));
                //IList<m_Cost_Center_Currency> ccc = (m_Cost_Center_Currency.status == 1).List<m_Cost_Center_Currency>();
                //foreach (m_Cost_Center_Currency HY in ccc)
                //{
                //    Account_Currency.Items.Add(new ListItem(HY.Cost_Center_Currency, HY.Cost_Center_Currency));
                //}

                SA_State_Province.Items.Clear();
                SA_State_Province.Items.Add(new ListItem("", ""));
                IList<m_State_Province> vras2 = (m_State_Province.status == 1).List<m_State_Province>();
                foreach (m_State_Province vra in vras2)
                {
                    SA_State_Province.Items.Add(new ListItem(vra.State_Province, vra.State_Province));
                }

                //SA_Location.Items.Clear();
                //SA_Location.Items.Add(new ListItem("", ""));
                //IList<m_Vendor_Location> vras3 = (m_Vendor_Location.status == 1).List<m_Vendor_Location>();
                //foreach (m_Vendor_Location vra in vras3)
                //{
                //    SA_Location.Items.Add(new ListItem(vra.Location, vra.Location));
                //}


                #region 修改 Sub Business Unit  Add by Kim.Zheng 2016-08-18
                SA_Sub_Business_Unit.Items.Clear();
                SA_Sub_Business_Unit.Items.Add(new ListItem("", ""));
                IList<m_ConCur_SBU> sbulist = (m_ConCur_SBU.state == 1).List<m_ConCur_SBU>();
                foreach (m_ConCur_SBU sbu in sbulist)
                {
                    SA_Sub_Business_Unit.Items.Add(new ListItem(sbu.SubBusinessUnit, sbu.SubBusinessUnit));
                }
                #endregion

                IsLoaded = true;
                


                IsLoaded = true;
            }
        }
        #endregion

        #region 方法 数据验证
        private List<string> DataValidation()
        {
            
            List<Regular> regs = new List<Regular>();
            if (Actions.SelectedValue == "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, SA_First_Name.Text, "First Name(名) 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA_Last_Name.Text, "Last Name(姓) 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA_CTE_Login_Name.Text, "CTE Login Name（公司员工邮箱) 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA_Account_Activation_Date.Text, "Account Activation Date (报销账号开始时间) 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA_Employee_ID.Text, "Employee ID (HR系统中8位数值) 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA_State_Province.SelectedValue, "State/Province 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA_Legal_Entity.SelectedValue, "Legal Entity 公司代码(机构单位2) 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA_Cost_Object_Code.Text, "Cost Object Code成本对象代码 必填"));
                //Modified by Tony 2016-03-24,Hu Na Requested
                regs.Add(new Regular(RegularExp.NotEmpty, SA_Approver_Linemanager.Text, "Approver(报销审批人邮箱) 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA_SWIFT_BIN.Text, "SWIFT/BIN (银行清算代码) 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA_IBAN_Number.Text, "EIBAN number (银行账号号码) 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA_Location.SelectedValue, "Location 必填"));
                if (SA_Employee_ID.Text.Length != 8)
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, "", "Employee ID 长度只能8位！"));
                }

                if (SA_SWIFT_BIN.Text.Length != 12)
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, "", "SWIFT/BIN 长度只能12位！"));
                }
               
                
            }
            if (Actions.SelectedValue != "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, SA_CTE_Login_Name.Text, "CTE Login Name（公司员工邮箱) 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA_Employee_ID.Text, "Employee ID (HR系统中8位数值) 必填"));
                if (SA_Employee_ID.Text.Length != 8)
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, "", "Employee ID 长度只能8位！"));
                }
            }

            regs.Add(new Regular(RegularExp.NotEmpty, SA_Sub_Business_Unit.SelectedValue, "Sub Business Unit 必填")); //add by kim.zheng 2016-08-18
            
            return Validation(regs);
        }
        #endregion

        #region 重载 OnLoadComplete
        protected override void OnLoadComplete(EventArgs e)
        {
            if (!IsLoaded && TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit)
            {
                Actions_SelectedIndexChanged(null, e);
            }

            base.OnLoadComplete(e);
        }
        #endregion      

        #region 方法 SetDropDownListValue
        private void SetDropDownListValue(Anthem.DropDownList drpT, object o)
        {
            try
            {
                if ((TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) || drpT.Items.FindByValue(o.ToString()) != null)
                {
                    drpT.SelectedValue = o.ToString();
                    return;
                }

                drpT.Items.Add(new ListItem(o.ToString(), o.ToString()));
                drpT.SelectedIndex = 0;

            }
            catch (Exception)
            {
            }
        }
        #endregion

        protected void SA_CTE_Login_Name_TextChanged(object sender, EventArgs e)
        {
            SA_Email_Address.Text = SA_CTE_Login_Name.Text;
        }

        protected void SA_Employee_ID_TextChanged(object sender, EventArgs e)
        {
            SA_Local_Personnel_Number.Text = SA_Employee_ID.Text;
        }

       


    }
}